﻿using System;
using Bookvar.ObjectModel;
using Bookvar.ObjectModel.Actions;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Bookvar.UnitTests.ObjectModel.Actions
{
    /// <summary>
    /// Common tests for all actions.
    /// </summary>
    [TestClass]
    public class CommonActionTests
    {
        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext { get; set; }

        /// <summary>
        /// Creates the action that will be tested. Its inheritor should implement this method 
        /// and return a properly constructed concrete action.
        /// </summary>
        /// <returns></returns>
        protected virtual IAction CreateAction()
        {
            // HACK: this is done because the class could not be abstract due to a problem with MSTEST.
            // see: http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=3429584&SiteID=1
            return new ChangeTopicAction( new Topic() );
        }

        [TestMethod]
        [ExpectedException( typeof ( InvalidOperationException ) )]
        public void Undo_WithoutExecuteFirst_Throws()
        {
            IAction action = CreateAction();
            action.Undo();
        }

        [TestMethod]
        [ExpectedException( typeof ( InvalidOperationException ) )]
        public void Execute_TwiceWithNoUndo_Throws()
        {
            IAction action = CreateAction();
            action.Execute();
            action.Execute();
        }
    }
}